package com.starleague.battletech.unit.mech;

import com.starleague.battletech.BattletechException;
import com.starleague.battletech.unit.IWeight;
import com.starleague.battletech.unit.WeightUtil;

public abstract class AbstractMechGyroFactory
{
    public final IMechGyro addGyro(IMutableMech mech,
                                   MechGyroType gyroType) throws BattletechException
    {
        IWeight gyroWeight = calcGyroWeight(mech, gyroType);
        return addGyro(mech, gyroWeight, gyroType);
    }

    protected abstract IMechGyro addGyro(IMutableMech mech,
                                         IWeight gyroWeight,
                                         MechGyroType gyroType) throws BattletechException;

    private IWeight calcGyroWeight(IMech mech,
                                   MechGyroType gyroType) throws BattletechException
    {
        switch (gyroType)
        {
            case NORMAL:
                return WeightUtil.roundUp(mech.getEngine().getEngineRating() / 100.0);
        }

        throw new BattletechException("Unknown MechGyroType: " + gyroType);
    }
}
